<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>管理后台</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- 引入外部头文件 -->
    <include file="layout/header" />
    <!-- 当前文件定制 -->
    <link rel="stylesheet" href="__PUBLIC__/plugins/datatables/dataTables.bootstrap.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="__PUBLIC__/plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="__PUBLIC__/plugins/daterangepicker/daterangepicker-bs3.css">
    <!-- <link rel="stylesheet" href="__PUBLIC__/plugins/datatables/select.bootstrap.min.css"> -->
    <!-- ／定制结束 -->
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
  <style type="text/css">
 a{
    cursor: pointer
 }
  </style>
</head>

<body class="hold-transition skin-blue sidebar-mini ">
    <div class="wrapper">
        <!-- 菜单 -->
        <include file="layout/menu" name="超级管理员" />
        <!-- ／导航菜单 -->
        <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">
                <h1>商品管理<small>商品状态</small></h1>
                <ol class="breadcrumb">
                    <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
                    <li><a href="#">管理</a></li>
                    <li class="active">商品</li>
                </ol>
            </section>
            <!-- Main content -->
            <section class="content">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="box box-primary">
                            <div class="box-header with-border">
                                <h3 class="box-title">投诉商品管理</h3>
                                <div class="box-tools pull-right">
                                    <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                                    </button>
                                    <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                                </div>
                            </div>
                            <!-- /.box-header -->
                            <div class="box-body">
                                <table id="goodlist" class="table table-bordered table-hover">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th class="select-filter">商品名</th>
                                            <th>商家</th>
                                            <th>买家</th>
                                            <th>创建时间</th>
                                            <th>状态</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    </tbody>
                                </table>
                            </div>
                            <!-- /.box-body -->
                        </div>
                        <!-- /.box -->
                    </div>
                    <div class="col-xs-12">
                        <div class="box box-primary">
                            <div class="box-header with-border">
                                <h3 class="box-title">商品管理</h3>
                                <div class="box-tools pull-right">
                                    <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                                    </button>
                                    <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                                </div>
                            </div>
                            <!-- /.box-header -->
                            <div class="box-body">
                                <ul class="products-list product-list-in-box">
                                    <if condition="count($list) neq 0">
                                        <volist name='list' id='item'>
                                            <li class="item">
                                                <div class="product-img">
                                                    <img src="__PUBLIC__/Uploads/good/{$item.pic_path}200x200/{$item.pic_name}" alt="Product Image">
                                                </div>
                                                <div class="product-info">
                                                    <a href="__APP__/Home/superuser/good/getDetail/id/{$item.good_id}" class="product-title">{$item.gname}
                      <span class="label label-warning pull-right">{$item.price}</span></a>
                                                    <span class="product-description">{$item.description}</span>
                                                </div>
                                            </li>
                                        </volist>
                                        <else />
                                    </if>
                                </ul>
                            </div>
                            <!-- /.box-body -->
                            <div class="box-footer text-center">
                                <a href="" class="uppercase">View All Products</a>
                            </div>
                            <!-- /.box-footer -->
                        </div>
                        <!-- /.box -->
                    </div>
                </div>
            </section>
        </div>
        <!-- /.col -->
        <include file="layout/copyright" />
    </div>
    <!-- /.content-wrapper -->
    <!-- ./wrapper -->
    <!-- REQUIRED JS SCRIPTS -->
    <!-- 外头文件 -->
    <include file="layout/footer" />
    <!-- 当前定制 -->
    <script src="__PUBLIC__/plugins/datatables/jquery.dataTables.min.js"></script>
    <script src="__PUBLIC__/plugins/datatables/dataTables.bootstrap.min.js"></script>
    <!-- daterangepicker -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js"></script>
    <script src="__PUBLIC__/plugins/daterangepicker/daterangepicker.js"></script>
    <!-- datepicker -->
    <script src="__PUBLIC__/plugins/datepicker/bootstrap-datepicker.js"></script>
    <!-- DOM 操作 -->
    <script>
    $(document).ready(function() {

        var table = $('#goodlist').DataTable({
            "ajax": {
                "url": "__APP__/Home/superuser/good/arguelist",
                "data": function(d) {
                    //添加额外的参数传给服务器
                    d.startdate = $('#reportrange span').data('start');
                    d.enddate = $('#reportrange span').data('end')
                }
            },
            "processing": true,
            "serverSide": true,
            // "dom": 'lrtip',
            "paging": true,
            // "lengthChange": false,
            // "searching": true,
            // "ordering": true,
            // "info": true,
            // "autoWidth": true,
            // "bFilter": true,
            "columns": [{
                "data": null
            }, {
                "data": "gname"
            }, {
                "data": "sname"
            }, {
                "data": "uname"
            }, {
                "data": "datetime"
            }, {
                "data": 'status'
            }, {
                "data": null
            }],
            "columnDefs": [{
                "render": function(data, type, row, meta) {
                    //渲染 把数据源中的标题和url组成超链接
                    return '<a href="__APP__/Home/superuser/good/getDetail/id/' + row.gid + '" target="_blank">' + data + '</a>';
                },
                //指定是第三列
                "targets": 1
            }, {
                "render": function(data, type, row, meta) {
                    //渲染 把数据源中的标题和url组成超链接
                    return '<a href="__APP__/Home/Superuser/Shop/shopprofile/id/' + row.sid + '" target="_blank">' + data + '</a>';
                },
                //指定是第三列
                "targets": 2
            }, {
                "render": function(data, type, row, meta) {
                    //渲染 把数据源中的标题和url组成超链接
                    return '<a href="__APP__/Home/Superuser/User/checkUserProfile/userid/' + row.uid + '" target="_blank">' + data + '</a>';
                },
                //指定是第三列
                "targets": 3
            }, {
                "render": function(data, type, row, meta) {
                    //渲染 把数据源中的标题和url组成超链接
                    // return '<a href="' + data + '" target="_blank">' + row.title + '</a>';
                    return (row.status==1 ? '<span class="label label-info">已处理</span>':'<span class="label label-warning">待处理</span>') ;
                },
                //指定是第三列
                "targets": 5
            }, {
                "render": function(data, type, row, meta) {
                    //渲染 把数据源中的标题和url组成超链接
                    // return '<a href="' + data + '" target="_blank">' + row.title + '</a>';
                    return (row.status==1?'<a onclick="tagdone(' + row.id + ',0)">标为待处理</a>':'<a onclick="tagdone(' + row.id + ',1)">标为已处理</a>');
                },
                //指定是第三列
                "targets": 6
            }], //第一列与第二列禁止排序
            "fnDrawCallback": function() {　　
                var api = this.api();　　
                var startIndex = api.context[0]._iDisplayStart; //获取到本页开始的条数
                　　
                api.column(0).nodes().each(function(cell, i) {　　　　
                    cell.innerHTML = startIndex + i + 1;　　
                });
            },
            "order": [[5,'asc'],[ 4, "desc" ]],
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sProcessing": '<div class="overlay"><i class="fa fa-refresh fa-spin"></i></div>',
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "sZeroRecords": "没有检索到数据",
                "sSearch": "搜索:",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                }
            },
            initComplete: initComplete,
            "dom": "<'row'<'col-md-9'l<'#mytoolbox'>><'col-md-3'f>r>" +
                "t" +
                "<'row'<'col-md-6'i><'col-md-6'p>>",
        });

        /**
         * 表格加载渲染完毕后执行的方法
         * @param data
         */
        function initComplete(data) {

            var dataPlugin =
                '<div id="reportrange" class="pull-left dateRange" style="width:400px;"> ' +
                '日期：<i class="glyphicon glyphicon-calendar fa fa-calendar"></i> ' +
                '<span id="searchDateRange"></span>  ' +
                '<b class="caret"></b></div> ';
            $('#mytoolbox').append(dataPlugin);
            //时间插件
            $('#reportrange span').html(moment().subtract('hours', 1).format('YYYY-MM-DD HH:mm:ss') + ' - ' + moment().format('YYYY-MM-DD HH:mm:ss'));

            $('#reportrange').daterangepicker({
                ranges: {
                    '今天': [moment(), moment()],
                    '昨天': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                    '最近 7 天': [moment().subtract(6, 'days'), moment()],
                    '最近 30 天': [moment().subtract(29, 'days'), moment()],
                    '这个月': [moment().startOf('month'), moment().endOf('month')],
                    '上个月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
                },
                startDate: moment().subtract(29, 'days'),
                endDate: moment(),
                locale: {
                    applyLabel: '确定',
                    cancelLabel: '取消',
                    fromLabel: '起始时间',
                    toLabel: '结束时间',
                    customRangeLabel: '自定义',
                    daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
                    monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
                        '七月', '八月', '九月', '十月', '十一月', '十二月'
                    ],
                    firstDay: 1
                }
            }, function(start, end, label) {
                $('#reportrange span').data('start', start.format('YYYY-MM-DD HH:mm:ss'));
                $('#reportrange span').data('end', end.format('YYYY-MM-DD HH:mm:ss'));
                $('#reportrange span').html(start.format('YYYY-MM-DD HH:mm:ss') + ' - ' + end.format('YYYY-MM-DD HH:mm:ss'));
            });



            //选择时间后触发重新加载的方法
            $("#reportrange").on('apply.daterangepicker', function() {
                //当选择时间后，出发dt的重新加载数据的方法
                table.ajax.reload();
                //获取dt请求参数
                var args = table.ajax.params();
            });

            function getParam(url) {
                var data = decodeURI(url).split("?")[1];
                var param = {};
                var strs = data.split("&");

                for (var i = 0; i < strs.length; i++) {
                    param[strs[i].split("=")[0]] = strs[i].split("=")[1];
                }
                return param;
            }

        }

        tagdone = function (id,status) {
            $.get('__APP__/Home/superuser/good/tagdone/id/' + id+'/status/'+status, function() {
                table.ajax.reload();
            });
        }

    });
    </script>
</body>

</html>